package com.jdk.demo.io.so_rcvbufDemo;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

	public static void main(String[] args) throws Exception {
		ServerSocket serverSocket = new ServerSocket();
		System.out.println("A server serverSocket.getReceiveBufferSize()=" + serverSocket.getReceiveBufferSize());
		serverSocket.setReceiveBufferSize(66);
		System.out.println("B server serverSocket.getReceiveBufferSize()=" + serverSocket.getReceiveBufferSize());
		serverSocket.bind(new InetSocketAddress("localhost", 8088));
		Socket socket = serverSocket.accept();
		InputStream inputStream = socket.getInputStream();
		InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
		char[] charArray = new char[1024];
		int readLength = inputStreamReader.read(charArray);
		while(readLength != -1) {
			String newString = new String(charArray, 0, readLength);
			System.out.println(newString);
			readLength = inputStreamReader.read(charArray);
		}
		socket.close();
		serverSocket.close();
	}
	// 抓包的结果：
	// [syn] seq=0 win=8192 len=0
	// [syn, ack] seq=0 ack=1 win=66 len=0
	// [ack] seq=1 ack=1 win=8192 len=0
	// 63766->8088 [ack] seq=1 ack=1 win=8192 len=66
	// 8088->63766 [ack] seq=1 ack=67 win=66 len=0
	// 63766->8088 [ack] seq=67 ack=1 win=8192 len=66
	// 8088->63766 [ack] seq=1 ack=133 win=66 len=0
	// 63766->8088 [ack] seq=133 ack=1 win=8192 len=66
	// 8088->63766 [ack] seq=1 ack=199 win=66 len=0
	// 63766->8088 [ack] seq=133 ack=1 win=8192 len=66
	// 8088->63766 [ack] seq=1 ack=199 win=66 len=0
	// 63766->8088 [ack] seq=199 ack=1 win=8192 len=66
	// 8088->63766 [ack] seq=1 ack=265 win=66 len=0
	// 63766->8088 [ack] seq=265 ack=1 win=8192 len=66
	// 8088->63766 [ack] seq=1 ack=331 win=66 len=0
	// 服务端只是告诉客户端，下一次客户端向服务端传输数据的windowSize窗口大小，但并没有更改客户端的接收缓冲区的大小，只是更改了服务端接口缓冲区的大小

}
